package com.screwdriver.jso.client.converter;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayNumber;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: jan kowalski
 * Date: 27.08.11
 * Time: 23:31
 * To change this template use File | Settings | File Templates.
 */
public class DateConverter {

    public static double toJsoValue(Date date) {
        return date.getTime();
    }

    public static Date toJavaValue(double time) {
        return new Date((long) time);
    }

    public static JsArrayNumber toJsoValue(Date[] e) {
        if (e == null)
            return null;

        JsArrayNumber array = (JsArrayNumber) JavaScriptObject.createArray();
        for (Date b : e) {
            array.push(toJsoValue(b));
        }

        return array;
    }

    public static Date[] toJavaValue(JsArrayNumber jsArrayString) {
        if (jsArrayString == null)
            return null;
        Date[] bigDecimals = new Date[jsArrayString.length()];
        for (int i = 0; i < jsArrayString.length(); i++) {
            bigDecimals[i] = toJavaValue(jsArrayString.get(i));
        }
        return bigDecimals;
    }
}
